﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="InventoryManagementSystem.SellPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:InventoryManagementSystem"
    xmlns:common="using:InventoryManagementSystem.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:converter="using:Infrastructure.Converter"
    mc:Ignorable="d"
    Loaded="page_Loaded">
    <common:LayoutAwarePage.Resources>
        <converter:DecimalToStringConverter x:Key="DecimalToStringConverter"/>
    </common:LayoutAwarePage.Resources>
    <Grid Style="{StaticResource LayoutRootStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/>
            <TextBlock x:Name="pageTitle" Grid.Column="1" Text="销售" Style="{StaticResource PageHeaderTextStyle}"/>
            <StackPanel Grid.Column="2" Orientation="Horizontal" Margin="0, 0, 0, 20" HorizontalAlignment="Right" VerticalAlignment="Bottom">
                <Button BorderThickness="0" Click="scanBarCode_Click">
                    <StackPanel>
                        <Path Stretch="Uniform" Fill="#FFFFFFFF" Width="64" Height="64" Data="M0,48.221001C0.42187881,48.4034,0.88282108,48.512703,1.3724532,48.512703L42.810287,48.512703C43.299792,48.512703,43.760795,48.4034,44.183997,48.221001L43.497794,51.833C43.497794,52.5882,42.883185,53.203999,42.122779,53.203999L2.0599594,53.203999C1.3006721,53.203999,0.6875062,52.5882,0.68750572,51.833z M23.906834,34.223999L31.549031,34.223999 37.044,43.581001 21.160999,43.581001z M12.19531,32.963486C11.584605,32.963486,11.411603,33.400982,10.927199,34.071472L4.2850688,44.21994C4.2850688,44.83173,4.7784834,45.324024,5.3892088,45.324024L22.089899,45.324024 38.790549,45.324024C39.401256,45.324024,39.898761,44.83173,39.898761,44.21994L33.2555,34.071472C32.772395,33.400982,32.599294,32.963486,31.987189,32.963486L22.089899,32.963486z M9.8151485,31.875L22.089899,31.875 34.36741,31.875C35.127917,31.875,35.340018,32.421894,35.943025,33.249981L44.183997,45.839619C44.183997,46.597507,43.567893,47.211998,42.810287,47.211998L22.089899,47.211998 1.3724532,47.211998C0.61462975,47.211998,0,46.597507,0,45.839619L8.2407948,33.249981C8.8397999,32.421894,9.0558719,31.875,9.8151485,31.875z M9.6149019,0L22.089992,0 34.5678,0C35.328399,0,35.943,0.61462402,35.943,1.37366L35.943,29.3046C35.943,30.0625,35.328399,30.677,34.5678,30.677L22.089992,30.677 9.6149019,30.677C8.8557507,30.677,8.2410003,30.0625,8.2410001,29.3046L8.2410001,1.37366C8.2410003,0.61462402,8.8557507,0,9.6149019,0z"/>
                        <TextBlock TextAlignment="Center">扫描条码</TextBlock>
                    </StackPanel>
                </Button>
                <Button BorderThickness="0" Click="printOrderButton_Click">
                    <StackPanel>
                        <Path Stretch="Uniform" Fill="#FFFFFFFF" Width="64" Height="64" Data="M13.338,28.512001L50.661999,28.512001 50.661999,52.741999 13.338,52.741999z M0,6.9750004L9.1771202,6.9750004 9.1771202,13.338428 54.944,13.338428 54.944,6.9750004 64,6.9750004 64,35.609999 54.944,35.609999 54.944,24.107311 9.1771202,24.107311 9.1771202,35.609999 0,35.609999z M13.277,0L50.723,0 50.723,9.4230003 13.277,9.4230003z"/>
                        <TextBlock TextAlignment="Center">打印订单</TextBlock>
                    </StackPanel>
                </Button>
                <Grid Width="50"/>
            </StackPanel>
        </Grid>
        <StackPanel Grid.Row="1" Margin="120, 0, 120, 50">
            <Grid >
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="2*"/>
                    <ColumnDefinition Width="2*"/>
                    <ColumnDefinition Width="1*"/>
                    <ColumnDefinition Width="1*"/>
                    <ColumnDefinition Width="1*"/>
                    <ColumnDefinition Width="1*"/>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" FontSize="24" TextAlignment="Center" Text="条形码"/>
                <TextBlock Grid.Column="1" FontSize="24" TextAlignment="Center" Text="品名"/>
                <TextBlock Grid.Column="2" FontSize="24" TextAlignment="Center" Text="单价"/>
                <TextBlock Grid.Column="3" FontSize="24" TextAlignment="Center" Text="数量"/>
                <TextBlock Grid.Column="4" FontSize="24" TextAlignment="Center" Text="总价"/>
                <TextBlock Grid.Column="5" FontSize="24" TextAlignment="Center" Text="操作"/>
            </Grid>

            <ScrollViewer ZoomMode="Disabled" FontSize="24" VerticalScrollBarVisibility="Auto">
                <ItemsControl ItemsSource="{Binding Orders}">
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Grid >
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="2*"/>
                                    <ColumnDefinition Width="2*"/>
                                    <ColumnDefinition Width="1*"/>
                                    <ColumnDefinition Width="1*"/>
                                    <ColumnDefinition Width="1*"/>
                                    <ColumnDefinition Width="1*"/>
                                </Grid.ColumnDefinitions>
                                <TextBlock Grid.Column="0" FontSize="24" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding Path=Product.BarCode}"/>
                                <TextBlock Grid.Column="1" FontSize="24" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding Path=Product.Name}"/>
                                <TextBlock Grid.Column="2" FontSize="24" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding Path=UnitPrice}"/>
                                <TextBlock Grid.Column="3" FontSize="24" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding Path=Count}"/>
                                <TextBlock Grid.Column="4" FontSize="24" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding Path=TotalPrice}"/>
                                <Button Grid.Column="5"  VerticalAlignment="Center" Style="{StaticResource RemoveAppBarButtonStyle}" Tag="{Binding}" Click="removeItemButton_Click"/>
                            </Grid>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel/>
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                </ItemsControl>
            </ScrollViewer>

            <Grid DataContext="{Binding Order}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="2*"/>
                    <ColumnDefinition Width="2*"/>
                    <ColumnDefinition Width="1*"/>
                    <ColumnDefinition Width="1*"/>
                    <ColumnDefinition Width="1*"/>
                    <ColumnDefinition Width="1*"/>
                </Grid.ColumnDefinitions>
                <TextBox x:Name="productBarCodeTextBox" Grid.Column="0" FontSize="24" HorizontalContentAlignment="Center" VerticalAlignment="Center" Text="{Binding Path=Product.BarCode,Mode=TwoWay}" KeyDown="productBarCodeTextBox_KeyDown" TextChanged="productBarCodeTextBox_TextChanged" GotFocus="TextBox_GotFocus"/>
                <TextBlock Grid.Column="1" FontSize="24" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding Path=Product.Name}"/>
                <TextBlock Grid.Column="2" FontSize="24" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding Path=UnitPrice}"/>
                <TextBox x:Name="orderCountTextBox" Grid.Column="3" FontSize="24" HorizontalContentAlignment="Center" VerticalAlignment="Center" Text="{Binding Path=Count,Mode=TwoWay,Converter={StaticResource DecimalToStringConverter}}" KeyDown="orderCountTextBox_KeyDown" GotFocus="TextBox_GotFocus"/>
                <TextBlock Grid.Column="4" FontSize="24" HorizontalAlignment="Center" Text="{Binding Path=TotalPrice}"/>
                <StackPanel Grid.Column="5" Orientation="Horizontal" HorizontalAlignment="Center">
                    <Button x:Name="addNewItemButton" Style="{StaticResource AddAppBarButtonStyle}" Margin="-15, -15, -15, -15" Click="addNewItemButton_Click"/>
                    <Button x:Name="discardNewItemButton" Style="{StaticResource DiscardAppBarButtonStyle}" Margin="-15, -15, -15, -15" Click="discardNewItemButton_Click"/>
                </StackPanel>
            </Grid>

            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0, 50, 0, 0">
                <Button x:Name="checkoutButton" BorderThickness="0" Click="checkoutButton_Click">
                    <StackPanel>
                        <Path  Stretch="Uniform" Fill="#FFFFFFFF" Width="64" Height="64" Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5" Data="M58.176777,26.829075C58.47649,26.833259,58.759991,27.012973,58.877216,27.306997L59.847118,29.691175C60.00732,30.087703,59.817318,30.531837,59.42532,30.692548L49.082989,34.901863C48.68969,35.063976,48.241688,34.875164,48.082985,34.483333L47.111485,32.094455C46.950184,31.703025,47.140182,31.256492,47.533386,31.09758L57.877213,26.885666C57.975163,26.845787,58.07687,26.827678,58.176777,26.829075z M57.167923,24.683122C57.546432,24.689113,57.904846,24.916862,58.055298,25.290353L58.373001,26.065735C58.113796,26.028637,57.841492,26.054035,57.583988,26.157533L47.23481,30.368332C46.445694,30.691925,46.062889,31.598802,46.385796,32.392383L47.31921,34.68993 45.791885,35.308315C45.496479,35.43071,45.180073,35.381912,44.926067,35.222416L34.729294,39.373417C34.528889,39.453514,34.315086,39.420314,34.143383,39.316719L29.323,38.973625 32.539253,35.359111C32.583557,35.165718,32.71106,34.992622,32.908863,34.914524L43.112236,30.759622C43.185238,30.471229,43.372742,30.214636,43.669449,30.094339L56.789673,24.753868C56.913349,24.703769,57.041752,24.681125,57.167923,24.683122z M42.066566,16.710197C41.657299,16.728662 41.265518,16.988847 41.103859,17.530088 40.529564,19.444797 40.512863,20.166801 40.267963,21.495006 39.21067,20.909004 38.156078,19.901798 37.119381,19.255996 36.536087,18.890695 35.689892,19.171396 35.445095,19.960399 35.083195,21.134905 35.434692,22.279411 35.489395,23.397316 34.195103,22.764515 32.989407,22.01511 31.833216,21.110805 31.074018,20.517702 30.162525,21.052204 29.946224,21.875108 29.463228,23.705217 29.083231,26.656433 29.258728,28.530742 29.406128,30.04775 31.744616,29.767149 31.602514,28.25934 31.503616,27.211034 31.843613,24.936424 31.921713,23.89932 33.184704,24.721523 34.572697,25.632328 35.990589,26.198131 36.534985,26.418131 37.347282,26.199331 37.534981,25.574327 37.836781,24.544422 37.517982,23.129717 37.429482,22.122511 38.385174,22.792514 39.412472,23.82632 40.554462,24.211021 41.16246,24.418821 41.835556,24.212421 42.097256,23.589317 42.797749,21.920011 42.95155,20.216901 43.27425,18.450092 43.47937,17.320087 42.74868,16.67942 42.066566,16.710197z M39.455471,8.216231L7.7354245,21.041805 8.6223898,23.233316 40.336765,10.407653z M41.885155,0L51.397999,23.521019 9.5130043,40.456001 0,16.938284z"/>
                        <TextBlock TextAlignment="Center">结账</TextBlock>
                    </StackPanel>
                </Button>
                <Button BorderThickness="0" Click="discardButton_Click">
                    <StackPanel>
                        <Path  Stretch="Uniform" Fill="#FFFFFFFF" Width="64" Height="64" Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5" Data="M33.978,27.679999L33.978,58.098995 41.374,58.098995 41.374,27.679999z M14.841001,27.679999L14.841001,58.098995 22.237,58.098995 22.237,27.679999z M4.0320003,22.430001L52.183002,22.430001 52.183002,63.995998 4.0320003,63.995998z M15.974001,0L40.194999,0 40.194999,7.7200003 56.166999,7.7200003 56.166999,15.995 0,15.995 0,7.7200003 15.974001,7.7200003z"/>
                        <TextBlock TextAlignment="Center">清除</TextBlock>
                    </StackPanel>
                </Button>
            </StackPanel>
        </StackPanel>
    </Grid>
</common:LayoutAwarePage>
